﻿ko.dotTemplateEngine = function () { };

ko.dotTemplateEngine.prototype = ko.utils.extend(new ko.templateEngine(), {
    renderTemplateSource: function (templateSource, bindingContext, options) {
        var precompiled = templateSource['data']('precompiled');

        if (!precompiled) {
            precompiled = doT.template("{{ with(it) { with(it.$data) { }}" + templateSource.text() + "{{ } } }}");

            templateSource['data']('precompiled', precompiled);
        }

        var renderedMarkup = precompiled(bindingContext).replace(/\s+/g, " ");
        return ko.utils.parseHtmlFragment(renderedMarkup);
    },
    createJavaScriptEvaluatorBlock: function (script) {
        return "{{=" + script + "}}";
    }
});

ko.setTemplateEngine(new ko.dotTemplateEngine());